package com.coded2.mobileposto.servlet;

import java.io.IOException;
import java.util.List;

import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ObjectWriter;

import com.coded2.infra.EntityManagerProvider;
import com.coded2.mobileposto.dao.PostoDAO;
import com.coded2.mobileposto.model.Posto;
import com.coded2.mobileposto.model.PostoCombustivel;
import com.coded2.mobileposto.model.Servico;
import com.google.gson.Gson;

/**
 * Servlet implementation class SyncServlet
 */
public class SyncServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		EntityManager em = EntityManagerProvider.getEntityManagerDefault();
		PostoDAO postoDAO = new PostoDAO();
		postoDAO.setEm(em);
		try {
			List<Posto> postos = postoDAO.search(new Posto());
			System.out.println(postos);
			ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
			resp.getWriter().write(ow.writeValueAsString(postos));
		} catch (Exception e) {
			throw new ServletException(e);
		}
		
		
		
	}
	
	
	
	

}
